package com.iyao_app.adapter;

import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.facebook.drawee.view.SimpleDraweeView;
import com.iyao_app.R;
import com.iyao_app.entry.StoryDetail;
import com.iyao_app.util.CountUtils;
import com.iyao_app.util.MarkUtil;
import com.iyao_app.util.TimeFormat;
import com.iyaowoqu.base_library.util.TimeUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.github.rockerhieu.emojicon.EmojiconTextView;

/**
 * 作者 :  胡家兵
 * 时间 :  2017/12/11.
 */

public class SignListAdapter_ extends BaseQuickAdapter<StoryDetail, SignListAdapter_.ViewHolder> {

    public SignListAdapter_(@Nullable List<StoryDetail> data) {
        super(R.layout.item_sign_, data);
    }

    @Override
    protected void convert(ViewHolder helper, StoryDetail item) {
        if (item.isLast) {
            helper.mLinTime.setVisibility(View.VISIBLE);
            helper.mTvTime.setText("哎吆, 没有更多了哦~ ");
            helper.mRlRoot.setVisibility(View.GONE);
            helper.mTvWeek.setText("");
        } else {
            helper.mRlRoot.setVisibility(View.VISIBLE);
            if (item.isNotDayStart) {
                helper.mLinTime.setVisibility(View.GONE);
            } else {
                helper.mLinTime.setVisibility(View.VISIBLE);
            }
            helper.mTvTime.setText(TimeFormat.getSignTime(item.createTime));
            helper.mTvWeek.setText(String.format("星期%s", TimeUtils.getChineseWeek(item.createTime)));

            helper.mSdvHead.setImageResource(MarkUtil.getId(item.typecode));


            helper.mTvName.setText(item.nickname);
            helper.mTvLocation.setText(item.sceneName);
            helper.mTvLike.setText(String.format("赞 (%s)", CountUtils.getCount(item.goodCount)));

            if (TextUtils.isEmpty(item.eventDesc)) {
                helper.mLinV2.setVisibility(View.GONE);
            } else {
                helper.mLinV2.setVisibility(View.VISIBLE);
                helper.mTvContent.setText(item.eventDesc);
            }
            if (item.eventFileUrlList != null && item.eventFileUrlList.size() > 0) {
                helper.mLinV3.setVisibility(View.VISIBLE);
                StaggeredGridLayoutManager layoutManager = null;
                OnlyPictureAdapter adapter = null;
                if (item.eventFileUrlList.size() == 0) {
                    layoutManager = new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL);
                    adapter = new OnlyPictureAdapter(item.eventFileUrlList);
                } else {
                    layoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
                    adapter = new OnlyPictureAdapter(item.eventFileUrlList);
                }
                helper.mRecyclerView.setAdapter(adapter);
                helper.mRecyclerView.setLayoutManager(layoutManager);

            } else {
                helper.mLinV3.setVisibility(View.GONE);
            }

        }

    }

    static class ViewHolder extends BaseViewHolder {

        @BindView(R.id.tv_time)
        TextView mTvTime;
        @BindView(R.id.tv_week)
        TextView mTvWeek;
        @BindView(R.id.lin_time)
        LinearLayout mLinTime;
        @BindView(R.id.v_line)
        View mVLine;
        @BindView(R.id.sdv_head)
        SimpleDraweeView mSdvHead;
        @BindView(R.id.tv_name)
        EmojiconTextView mTvName;
        @BindView(R.id.iv_tag)
        ImageView mIvTag;
        @BindView(R.id.tv_location)
        TextView mTvLocation;
        @BindView(R.id.iv_like)
        ImageView mIvLike;
        @BindView(R.id.tv_like)
        TextView mTvLike;
        @BindView(R.id.lin_v_1)
        LinearLayout mLinV1;
        @BindView(R.id.tv_content)
        EmojiconTextView mTvContent;
        @BindView(R.id.lin_v_2)
        LinearLayout mLinV2;
        @BindView(R.id.recyclerView)
        RecyclerView mRecyclerView;
        @BindView(R.id.lin_v_3)
        LinearLayout mLinV3;
        @BindView(R.id.rl_root)
        LinearLayout mRlRoot;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
